package main.java.com.study.设计模式.單例.study实现Map单例;

import java.util.HashMap;
import java.util.Map;

/**
 * map的單例模式
 * 線程安全的
 */
public class MyMapSync {

    private Map<Integer, Object> map = new HashMap<Integer, Object>();
    private Object lock = new Object();

    private static MyMapSync instance = new MyMapSync();

    private MyMapSync() {
    }

    public static MyMapSync getInstance() {
        return instance;
    }

    public void put(Integer taskId, String name) {
        synchronized (lock) {
            map.put(taskId, name);
        }
    }

    public Map<Integer, Object> getMap() {
        return map;
    }

}